package com.zsr.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zsr.example.entity.SysLog;
import com.zsr.example.entity.SysOperationLog;
import com.zsr.example.mapper.SysOperationLogMapper;
import com.zsr.example.service.SysOperationLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsr.example.vo.SysOptLogReq;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsr
 * @since 2022-03-26
 */
@Service
public class SysOperationLogServiceImpl extends ServiceImpl<SysOperationLogMapper, SysOperationLog> implements SysOperationLogService {

    @Override
    public void pageQueryView(Page<SysOperationLog> page, SysOptLogReq sysOptLogReq) {
        //MP 构建条件
        LambdaQueryWrapper<SysOperationLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(SysOperationLog::getGmtCreate);
        String userId = sysOptLogReq.getUserId();
        Integer optSystem = sysOptLogReq.getOptSystem();
        String optModule = sysOptLogReq.getOptModule();
        String optType = sysOptLogReq.getOptType();
        String ipAddress = sysOptLogReq.getIpAddress();

        String begin = sysOptLogReq.getBegin();
        String end = sysOptLogReq.getEnd();
        if (!StringUtils.isEmpty(optSystem)) wrapper.eq(SysOperationLog::getOptSystem, optSystem);
        if (!StringUtils.isEmpty(optModule)) wrapper.eq(SysOperationLog::getOptModule, optModule);
        if (!StringUtils.isEmpty(optType)) wrapper.eq(SysOperationLog::getOptType, optType);
        if (!StringUtils.isEmpty(ipAddress)) wrapper.eq(SysOperationLog::getIpAddress, ipAddress);
        if (!StringUtils.isEmpty(userId)) wrapper.eq(SysOperationLog::getUserId, userId);
        if (!StringUtils.isEmpty(begin)) wrapper.ge(SysOperationLog::getGmtCreate, begin);
        if (!StringUtils.isEmpty(end)) wrapper.le(SysOperationLog::getGmtCreate, end);

        baseMapper.selectPage(page, wrapper);
    }
}
